package br.edu.ufcg.dsc.actions.resource;

import org.apache.struts2.config.Result;
import org.apache.struts2.dispatcher.ServletDispatcherResult;

import br.edu.ufcg.dsc.domain.Resource;
import br.edu.ufcg.dsc.domain.resource.TechnicalReport;
import br.edu.ufcg.dsc.services.ResourceService;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

@Result(name = "success", type = ServletDispatcherResult.class, value = "/jsp/resource/technicalReport.jsp")
public class FindTechnicalReportAction extends ResourceDriven<TechnicalReport> implements Preparable, ModelDriven<TechnicalReport>{
	
	private int resourceId;
	private TechnicalReport technicalReport;
	
	private static final long serialVersionUID = 1L;

	public void prepare() throws Exception {
		Resource resource = ResourceService.find(resourceId);
		if (resource != null)
			technicalReport = new TechnicalReport(resource.getMarc());
		else technicalReport = new TechnicalReport();
	}

	public int getResourceId() {
		return resourceId;
	}

	public void setResourceId(int resourceId) {
		this.resourceId = resourceId;
	}

	public TechnicalReport getTechnicalReport() {
		return technicalReport;
	}

	public void setTechnicalReport(TechnicalReport TechnicalReport) {
		this.technicalReport = TechnicalReport;
	}

	public TechnicalReport createModel() {
		return technicalReport;
	}

	@Override
	public String execute(){		
		return SUCCESS;
	}

}
